import random
import re
import string

from sqlalchemy.orm import Session

from crud import PermissionAdminCrud


class PublicAdminController:
    @staticmethod
    def has_permission(port_id: int, function_path: str, db: Session):
        return PermissionAdminCrud.has_permission(port_id, f'/hems{function_path}', db)

    @staticmethod
    def check_phone_num(phone: str):
        rule1 = re.compile(r'^1[345678]\d{9}$')
        if (rule1.match(phone)):
            return True
        else:
            return False

    @staticmethod
    def generate_password():
        alphabet = string.ascii_letters + string.digits + string.punctuation
        password = ''.join(random.choice(alphabet) for _ in range(8))
        return password